#include "main.h"

void print (__HufTree * head, char* i,int flag)
{
	char ed[] = "1";
	char nu[] = "0";
	char* m = (char*) calloc (2,sizeof(char));
	if (!m) cl_exit (PRINT,MEMORY_ERR);
	if (i)	{	m = (char *) calloc (strlen(i) +2,sizeof(char));
		if (!m) cl_exit (PRINT,MEMORY_ERR);
		strcat (m,i);
	}
	if (flag == -1)	strcat (m,nu);
	if (flag == 1)	strcat (m,ed);
	if (head)	{
	if (head->left)	print (head->left,m,-1);
	if (!head->flag)	{	printf ("%s ",m);	printf ("%c %d\n",head->alpha,head->count);
	}
	if (head->right)	print (head->right,m,1);
	} else return;
}